package com.changgou.search.controller;

import com.changgou.search.service.ESManagerService;
import com.changgou.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.Set;

/**
 * @author wz
 * @company 公司
 * @create 2020-03-24 10:09
 */
@RestController
@RequestMapping("/sku_search")
public class SearchController {
    @Autowired
    private SearchService searchService;

    @Autowired
    private ESManagerService esManagerService;

    @GetMapping
    public Map search(@RequestParam Map<String,String> paramMap){
        //处理get特殊符号
        this.handlerSearchMap(paramMap);
        Map resultMap = searchService.search(paramMap);
        return resultMap;
    }

    private void handlerSearchMap(Map<String, String> paramMap) {
        Set<Map.Entry<String, String>> entries = paramMap.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            if (entry.getKey().startsWith("spec_")){
                paramMap.put(entry.getKey(),entry.getValue().replace("+","%2B"));
            }
        }
    }
}
